package net.oschina.app.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.MApp;
import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Tweet;
import net.oschina.app.bean.TweetLike;
import net.oschina.app.bean.User;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/6.
 * ?
 */

public class MessageZGWAdapter extends BaseRecyclerViewAdapter {
    public List<TweetLike> list;
    public MessageZGWAdapter(Context context, List<TweetLike> list) {
        super(context);
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.message_item_zhanguowo, null);
        MessageHolder messageHolder = new MessageHolder(view);
        return messageHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        TweetLike tweetLike = list.get(position);
        Tweet tweet = tweetLike.getTweet();
        User user = tweetLike.getUser();

        MessageHolder messageHolder = (MessageHolder) holder;
        messageHolder.mDesc.setText(tweet.getAuthor()+":"+tweet.getBody());
        Glide.with(MApp.mContext).load(user.getPortrait()).into(messageHolder.mFace);
        messageHolder.mName.setText(user.getName());
        messageHolder.mTime.setText(tweetLike.getDatatime());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MessageHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.mc_user_desc)
        TextView mDesc;
        @BindView(R.id.mc_user_name)
        TextView mName;
        @BindView(R.id.mc_user_time)
        TextView mTime;
        @BindView(R.id.mc_user_face)
        ImageView mFace;
        public MessageHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
